package Config;

import com.alibaba.druid.pool.DruidDataSource;
import org.apache.ibatis.datasource.DataSourceFactory;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.TransactionManagementConfigurationSelector;

import javax.sql.DataSource;

@Component
public class MyBaits {
    @Bean
    public DataSource GetDataSource(){
        DruidDataSource aas=new DruidDataSource();
        aas.setDriverClassName("com.mysql.cj.jdbc.Driver");
        aas.setUrl("jdbc:mysql://127.0.0.1:3306/antpro");
        aas.setUsername("root");
        aas.setPassword("123456");
        return aas;
    }
    @Bean
    public SqlSessionFactoryBean GetBean(DataSource ds){
        SqlSessionFactoryBean ssb=new SqlSessionFactoryBean();
        ssb.setDataSource(ds);
        return  ssb;
    }
    @Bean
    public MapperScannerConfigurer GetMs(){
        MapperScannerConfigurer msc=new MapperScannerConfigurer();
        msc.setBasePackage("Dao");
        return msc;
    }
    //开启事务
//    @Bean
//    public DataSourceTransactionManager GetDSTM(DataSource ds){
//        DataSourceTransactionManager DSTM=new DataSourceTransactionManager();
//        DSTM.setDataSource(ds);
//        return DSTM;
//    }
}
